'''
Created on May 8, 2012
TC ID: Ecom_5049
Desc: Kiem thu chuc nang xoa bai kiem tra
@author: lavang
'''
import unittest
import time
from HTMLTestRunner import HTMLTestRunner
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.lessonInformationFunc import clickOnLesson
from Functions.testsFunc import clickOnTests, deleteTest,\
    isTestDeletedSuccessfully
   

username=readData("username",index=2)
password=readData("password",index=2)
tm_lesson=readData("lessonName",index=2)
tm_test=readData("testName",index=3)
tm_parentUnit=readData("subUnitName",index=2)
class Ecom_5047(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5047(self):
        print "Buoc 1: Dang nhap website"
        login(self,username,password)
        
        print "Buoc 2: Click vao mot bai hoc"
        clickOnLesson(self,tm_lesson)
        
        print "Buoc 3: Click vao 'Tests'"
        clickOnTests(self)
        
        print "Buoc 4: Xoa bai kiem tra"
        deleteTest(self,tm_test,tm_parentUnit)
        
        print "Buoc 5: Xac nhan xoa bai kiem tra thanh cong"
        self.assertFalse(isTestDeletedSuccessfully(self,tm_test,tm_parentUnit), "Failed!")
        print "Passed! Bai kiem tra duoc xoa thanh cong"
        
    def tearDown(self):
        endCondition(self)
        
    
    
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5047)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang xoa bai kiem tra'
                    )
    runner.run(suite)